package cn.dengta.webapp.trade.dao;

import cn.dengta.context.model.Language;
import cn.dengta.webapp.base.dao.BaseDao;
import cn.dengta.webapp.trade.entity.meta.MetaConfig;
import cn.dengta.webapp.trade.model.MetaConfigType;
import org.apache.ibatis.annotations.*;

/**
 * 系统前端资料配置表 Mapper 接口
 *
 * @author lgy
 * @since 2022-03-26
 */
public interface MetaConfigDao extends BaseDao<MetaConfig> {

	@Select("""
			SELECT * FROM dt_meta_config WHERE `language` = #{language} AND type = #{ruleType}
            AND id >= (SELECT FLOOR( MIN(id) + RAND() * (MAX(id) - MIN(id) + 1) ) FROM dt_meta_config WHERE `language` = #{language} AND type = #{ruleType})
            ORDER BY id LIMIT 1
			""")
	MetaConfig getRandomNickname(@Param("language") Language language, @Param("ruleType") MetaConfigType ruleType);

	@Delete("DELETE FROM dt_meta_config WHERE id = #{id} AND type = #{type}")
	void remove(@Param("id") Long id, @Param("type") Integer type);

}
